<template>
  <div class="classListList">
    <div class="classListListWrap">
      <div class="selectTime">
        <SelectDate @datebutton="selectDate" :key="randomStr" />
      </div>
      <div class="days">
        <div class="weeks">
          <div ref="week1">周一</div>
          <div>周二</div>
          <div>周三</div>
          <div>周四</div>
          <div>周五</div>
          <div>周六</div>
          <div>周日</div>
        </div>
        <div class="day">
          <div
            v-for="(item, index) in calenders"
            :key="index"
            :style="{width: calcWidth, color: item.month == nowMonth ? '' : 'rgba(153,153,153, .3)', background: item.month == nowMonth && active == item.day ? '#f1f1f9' : ''}"
            @click="clickDay(item)"
          >
            {{item.day}}
            <div class="dot" v-if="item.month == nowMonth && item.dot"></div>
          </div>
        </div>
      </div>
      <div class="course_wrap">
        <div class="course_item_wrap">
          <div class="records" v-if="courseList.length">
            <div class="item"
              v-for="item in courseList"
              :key="item.id"
              @click="clickDetail(item.courseNumber)"
            >
              <div class="records_item_title">{{item.courseName}}</div>
              <div class="records_item_detail">
                <div class="qixian">
                  <div class="detail_title">上课开始时间：</div>
                  <div class="num mainColor">{{item.startTime}}</div>
                </div>
                <div class="qixian">
                  <div class="detail_title">上课结束时间：</div>
                  <div class="num mainColor">{{item.endTime}}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="nodata" v-else>
            <van-empty description="暂无数据哦" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import SelectDate from '@/components/selectDate'
  export default {
    name: 'classListList',
    components: {
      SelectDate
    },
    data() {
      return {
        randomStr: new Date().getTime(),
        calcWidth: '',
        activeDate: '',
        active: '',
        nowMonth: '',
        calenders: [],
        courseList: []
      }
    },
    created() {
      this.studentId = this.$route.params.info.id
    },
    beforeRouteEnter(to, from, next) {
      if (from.path === '/selectStudent' || from.path === '/selectStudentWithTabbar') {
        to.meta.isBack = false;
      } else {
        to.meta.isBack = true;
      }
      next()
    },
    activated() {
      if (!this.$route.meta.isBack) {
        this.studentId = this.$route.params.info.id
        this.courseList = []
        this.active = ''
        this.randomStr = new Date().getTime()
        this.getData()
      }
    },
    mounted() {
      this.calcWidth = this.$refs.week1.clientWidth - 1.5 + 'px'
      this.$forceUpdate()
    },
    methods: {
      clickDetail(e) {
        this.$router.push({ name: 'common-product-detail', params: { id: e } })
      },
      clickDay(e) {
        if (e.month != this.nowMonth) return
        this.active = e.day
        this.getCourseByDay()
      },
      getCourseByDay() {
        this.$http.getCalendarCorseList({time: `${this.activeDate}-${this.active}`, studentId: this.studentId}).then(res => {
          this.courseList = res.data.result
        })
      },
      selectDate(e) {
        this.nowMonth = e.month < 10 ? '0'+e.month : e.month
        this.activeDate = `${e.year}-${e.month < 10 ? '0'+e.month : e.month}`
        this.active = ''
        this.getData()
      },
      getData() {
        this.$http.getCalendarCorse({studentId: this.studentId, time: this.activeDate}).then(res => {
          this.calenders = res.data.result
          // this.getCourseByDay()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .CENTER {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .classListList {
    color: #333;
    height: 100%;
    width: 100%;
    overflow: hidden;
    .classListListWrap {
      height: 100%;
      width: 100%;
      overflow: scroll;
      .selectTime {
        width: 100%;
        height: 50px;
        border-bottom: 1px solid rgba(222,222,222, .2);
        padding: 0px 20px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .selecMonth {
          width: 100px;
          height: 30px;
          border: 1px solid #dedede;
          border-radius: 30px;
          font-size: 12px;
          color: #999;
        }
      }
      .days {
        min-height: 285px;
        display: flex;
        flex-direction: column;
        align-items: center;
        background: rgba(241,241,249, .5);
        .weeks {
          display: flex;
          justify-content: center;
          width: 100%;
          font-size: 12px;
          padding: 0px 10px;
          box-sizing: border-box;

          div {
            flex: 1;
            height: 45px;
            display: flex;
            align-items: center;
            justify-content: center;
          }
          div:last-child {
            border-right: none;
          }
        }
        .day {
          display: flex;
          flex-wrap: wrap;
          width: 100%;
          font-size: 12px;
          padding: 0px 10px;
          box-sizing: border-box;
          div {
            width: 45px;
            height: 47px;
            background: #fff;
            border-bottom: 1px solid rgba(222,222,222, .2);
            border-right: 1px solid rgba(222,222,222, .2);
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            .dot {
              position: absolute;
              top: 5px; right: 5px;
              width: 4px; height: 5px;
              background: red;
              border-radius: 50%;
            }
          }
          div:nth-child(1) {
            border-left: 1px solid rgba(222,222,222, .2);
          }
          div:nth-child(7n+8) {
            border-left: 1px solid rgba(222,222,222, .2);
          }
        }
      }
      .course_wrap {
        width: 100%;
        height: calc(100% - 335px);
        padding: 15px;
        box-sizing: border-box;
        background: rgba(241, 241, 249, 0.5);
        .course_item_wrap {
          width: 100%;
          height: 100%;
          border-radius: 10px;
          .item {
            min-height: 100px;
            position: relative;
            margin-top: 15px;
            padding: 18px 20px;
            background: #fff;
            box-sizing: border-box;
            box-shadow: 0 4px 15px 0 rgba(0,0,0,0.09);
            border-radius: 4px;
            display: flex;
            flex-direction: column;
            .records_item_title {
              width: 100%;
              min-height: 25px;
              font-weight: 900;
              text-align: left;
              color: #333;
            }
            .records_item_detail {
              margin-top: 10px;
              flex: 1;
              .qixian:first-child {
                margin-bottom: 10px;
              }
              .qixian {
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: space-between;
              }
              .num {
                font-size: 14px;
                font-weight: bolder;
              }
              .detail_title {
                font-size: 12px;
                color: #999;
              }
            }
          }
          .item:first-child {
            margin-top: 0px;
          }
        }
        .nodata {
          width: 100%;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }

  }
</style>
